/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package javaapplication1;

import java.awt.*;
import java.awt.event.*;
import java.lang.Math.*;

/**
 *
 * @author Dell-Sid
 */
class Myframe2 implements ActionListener {

    Frame f2;
    Label l1, l2;
    TextField t1, t2;
    Button b1, b2, b3, b4;

    Myframe2(String s) {
        f2 = new Frame(s);
        f2.setLayout(null);
        f2.setBackground(Color.white);
        f2.setSize(700, 500);
        f2.setVisible(true);

        l1 = new Label("Enter no");
        l2 = new Label("Result is");

        b1 = new Button("Prime/not");
        b2 = new Button("Palimdrome");
        b3 = new Button("Factorial");
        b4 = new Button("Even/Odd");

        t1 = new TextField();
        t2 = new TextField();


        l1.setBounds(100, 200, 80, 20);
        t1.setBounds(200, 200, 80, 20);

        b1.setBounds(100, 260, 80, 50);
        b2.setBounds(200, 260, 80, 50);
        b3.setBounds(300, 260, 80, 50);
        b4.setBounds(400, 260, 80, 50);

        b1.addActionListener(this);
        b2.addActionListener(this);
        b3.addActionListener(this);
        b4.addActionListener(this);



        l2.setBounds(100, 350, 80, 20);
        t2.setBounds(200, 350, 80, 20);

        f2.add(l1);
        f2.add(l2);
        f2.add(t1);
        f2.add(t2);
        f2.add(b1);
        f2.add(b2);
        f2.add(b3);
        f2.add(b4);

    }

    public static void main(String k[]) {

        new Myframe2("Myframe2");

    }

    public void actionPerformed(ActionEvent m) {
        if (m.getSource() == b1) {
            int i;
            for (i = 2; i < (Math.sqrt(Integer.parseInt(t1.getText()))); i++) {

                t2.setText("Prime");

                if ((Integer.parseInt(t1.getText()) == 1)) {
                    t2.setText("Not");
                    break;
                } else if ((Integer.parseInt(t1.getText())) % i == 0) {
                    t2.setText("Not");
                    break;

                }

            }
        }

        if (m.getSource() == b2) {
            int i;


        }

        if (m.getSource() == b3) {
            int i;
            int fact = 1;

            for (i = 1; i <= Integer.parseInt(t1.getText()); i++) {
                fact = fact * i;

            }

            t2.setText(fact + " ");
        }
        if (m.getSource() == b4) {
            int i;
            String fact = "Odd";
            if (Integer.parseInt(t1.getText()) % 2 == 0) {
                fact = "Even";
            }

            t2.setText(fact + " ");
        }

    }
}
